<html>
<head>
    <meta charset="utf-8">
    <title>下载记录</title>
</head>
<body>

<?php
require_once "config.php";

//建立与mysql的连接
$mysqli = new mysqli(db_server, db_username, db_password, db_datebasename);
if ($mysqli->connect_errno) {
    die('连接数据库出错：' . $mysqli->connect_error);
}

//设置默认编码
$mysqli->set_charset('utf8');

//读取数据
$sql = "SELECT * FROM api.file";
$result = $mysqli->query($sql);
while ($row = $result->fetch_assoc()) {
    $num = $row['address1_num'] + $row['address2_num'];
    echo "文件" . $row['id'] . "下载次数：" . $num . "  " . "来源1：" . $row['address1_num'] . "  " . "来源2：" . $row['address2_num'];
    echo "<br/>";
}

$sql = "SELECT * FROM api.filelog";
$result = $mysqli->query($sql);
?>
<h2>下载记录</h2>
<div class="table-container">
    <table border="1" cellpadding=0 cellspacing=0>
        <tr>
            <th>id</th>
            <th>文件id</th>
            <th>文件来源</th>
            <th>浏览器</th>
            <th>操作系统</th>
            <th>来源地址</th>
            <th>ip</th>
            <th>时间</th>
        </tr>

        <?php while ($row = $result->fetch_assoc()){ ?>
        <tr>
            <td><?php echo $row['id'] ?> </td>
            <td><?php echo $row['fileid'] ?> </td>
            <td><?php echo $row['fileurl'] ?> </td>
            <td><?php echo $row['browser'] ?> </td>
            <td><?php echo $row['platform'] ?> </td>
            <td><?php echo $row['sourceurl'] ?> </td>
            <td><?php echo "<a href='ip.php?ip={$row['ip']}' target='_blank'>{$row['ip']}</a>" ?> </td>
            <td><?php echo $row['date'] ?> </td>
            <?php } ?>
        </tr>
    </table>
</div>
</body>
<style>
    .table-container {
        width: 100%;
        _overflow-x: auto;
        _overflow-y: auto;
        margin: 0 0 1em;
    }

    table {
        border: 0;
        border-collapse: collapse;
    }

    table td, table th {
        border: 1px solid #999;
        padding: .5em 1em
    }
</style>
</html>